//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xsl

package fms.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import fms.common.FieldInfo;
import fms.services.FieldService;
import fms.services.ServiceException;
import fms.services.ServiceManager;
import fms.web.form.AddfieldinfoForm;

/**
 * MyEclipse Struts Creation date: 11-25-2006
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/addfieldinfo" name="addfieldinfoForm"
 *                input="/form/addfieldinfo.jsp" scope="request" validate="true"
 * @struts.action-forward name="addfieldinfofail" path="/addfieldinfofail.jsp"
 * @struts.action-forward name="addfieldinfosucess"
 *                        path="/addfieldinfosucess.jsp"
 */
public class AddfieldinfoAction extends Action {

	// --------------------------------------------------------- Instance
	// Variables

	// --------------------------------------------------------- Methods

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AddfieldinfoForm addfieldinfoForm = (AddfieldinfoForm) form;

		System.out.print("jess");

		String field_id = addfieldinfoForm.getField_id();
		int field_type = addfieldinfoForm.getField_type().intValue();
		int field_capacity = addfieldinfoForm.getField_capacity().intValue();
		double field_price = addfieldinfoForm.getField_price().doubleValue();
		String field_status = addfieldinfoForm.getField_status();

		FieldService service = null;
		try {
			service = (FieldService) ServiceManager.getDefaultManager()
					.getService(FieldService.class);
		} catch (ServiceException e) {

			e.printStackTrace();
		}

		FieldInfo fieldinfo = new FieldInfo();
		fieldinfo.setFieldId(field_id);
		fieldinfo.setFieldType(field_type);
		fieldinfo.setFieldCapacity(field_capacity);
		fieldinfo.setFieldPrice(field_price);
		fieldinfo.setFieldStatus("unused");

		try {
			service.addField(fieldinfo);
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return mapping.findForward("addfieldinfosucess");
	}

}
